package com.example.hamilyjing.androiddemo.module.main.presenter;

import android.content.Context;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hamilyjing.androiddemo.module.main.MainActivity;
import com.example.hamilyjing.androiddemo.module.main.R;
import com.example.hamilyjing.androiddemo.service.homepageService.JJHomepageService;
import com.example.hamilyjing.androiddemo.service.homepageService.model.JJHomepageModel;
import com.mobileClientKernel.android.serviceManager.network.JJRequestError;
import com.mobileClientKernel.android.serviceManager.service.IJJServiceCallBack;
import com.mobileClientKernel.android.serviceManager.servicefactory.JJServiceFactory;

import org.json.JSONObject;

public class JJMainActivityPresenter {

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public String errMsg = "init";

    public void requestGetWeather(Context context, final IJJServiceCallBack callBack) {
        final JJMainActivityPresenter me = this;
        JJHomepageService homepageService = (JJHomepageService) JJServiceFactory.getInstance().getService(JJHomepageService.serviceName());
        homepageService.requestGetWeather(context, new IJJServiceCallBack() {
            @Override
            public void onNetworkRequestSuccess(Object model, JSONObject otherInfo) {
                JJHomepageModel homepageModel = (JJHomepageModel)model;
                if (homepageModel.isValid()) {
                    me.setErrMsg(homepageModel.errMsg);
                }

                callBack.onNetworkRequestSuccess(model, otherInfo);
            }

            @Override
            public void onNetworkRequestFailure(JJRequestError error, JSONObject otherInfo) {
                callBack.onNetworkRequestFailure(error, otherInfo);
            }
        });
    }
}
